﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cn.Edwon.Web.Support;
using System.Reflection;
using Cn.Cellula.Model;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Edwon.Web.Validation;
using Cn.Edwon.Web;
using Cn.Cellula.Biz;
using Cn.Cellula.Model.System;
using Cn.Cellula.Client;
namespace Cn.Cellula.Website.Admin.Content.Template {
    public partial class Edit : PageSupport {
        String EOKey = null;
        IUserBiz biz = BizFactory.Get<IUserBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            EOKey = Request.QueryString["id"];
            if (!Page.IsPostBack) {
                InitForm();
                if (!String.IsNullOrEmpty(EOKey)) {
                    FillForm(EOKey);
                }
            }
        }

        void InitForm() {
        }
        void FillForm(String key) {
            TSysTemplateEO eo = biz.Load<TSysTemplateEO>(key);
            this.txt_Content.Text = eo.TlContent;
            this.txt_TlName.Text = eo.TlName;
            this.txt_TlMemo.Text = eo.TlMemo;
        }

        protected void btn_save_Click(object sender, EventArgs e) {
            Boolean bk = QuickValidator.Execute(Request, this.txt_Content.Parent);
            if (!bk) {
                SiteInfo.Send(Page, TxtDef.ERROR, QuickValidator.Message);
                return;
            }
            if (String.IsNullOrEmpty(EOKey)) {
                TSysTemplateEO eo = new TSysTemplateEO();
                eo.TlName = this.txt_TlName.Text;
                eo.TlContent = this.txt_Content.Text;
                eo.OwnerKey = this.OwnerKey;
                eo.TlMemo = this.txt_TlMemo.Text;
                eo.CreateDate = DateTime.Now;
                eo.UpdateDate = DateTime.Now;
                eo.Operator = (base.Actor != null) ? base.Actor.ID : "unknown";
                biz.Save<TSysTemplateEO>(eo);
                BizFactory.Get<ILogBiz>().LogInsert("动作", eo.TlName, this.Actor, Request);
            } else {
                TSysTemplateEO eo = biz.Load<TSysTemplateEO>(EOKey);
                eo.TlName = this.txt_TlName.Text;
                eo.TlContent = this.txt_Content.Text;
                eo.TlMemo = this.txt_TlMemo.Text;
                eo.UpdateDate = DateTime.Now;
                eo.Operator = (base.Actor != null) ? base.Actor.ID : "unknown";
                biz.Update<TSysTemplateEO>(eo);
                BizFactory.Get<ILogBiz>().LogUpdate("动作", eo.TlName, this.Actor, Request);
            }
            Response.Redirect("List.aspx");
        }

    }
}
